#include <gtest/gtest.h>
#include "HiCommonLog.hpp"

static void debug(const char* file, const char* function, int line, const char* log) {
	printf("user defined log function:[%s::%s-%d] %s", file, function, line, log);
}

static void debug_ingore_test() {
	HI_DEBUG("we want this debug is not out");
	printf("we want  log out from this\n");
	hi_is_ignore_debug(false);
	HI_DEBUG("we want this debug is out:printf");
}

TEST(HiCommonLog, debug_ingore){
	printf("we want no log out put begin\n");
	debug_ingore_test();
	printf("we want no log out put end\n");
}

static void set_debug_test() {
	hi_set_debug(debug);
	HI_FUNC_DEBUG();
	HI_DEBUG("this is a hi_debug test, no parameters");
	HI_DEBUG("this is a hi_debug test, has two parameters=>1:%s, 2:%d", "first parameter", 256);
}
TEST(HiCommonLog, set_debug){
	printf("we want log out begin\n");
	set_debug_test();
	printf("we want log out end\n");
}

static bool isCalled = true;
static void debug2(const char* file, const char* function, int line, const char* log) {
	printf("user defined log function:[%s::%s-%d] %s", file, function, line, log);
	isCalled = true;
}

static void set_debug_after_ignore_test() {
	isCalled = true;
	hi_set_debug(debug2);
	HI_DEBUG("this debug is out\n we want no log out after this\n");
	hi_is_ignore_debug(true);
	isCalled = false;
	HI_DEBUG("this debug is out, means this test is failed");
	ASSERT_FALSE(isCalled);
	
	HI_FUNC_DEBUG();
	HI_DEBUG("this is a hi_debug test, no parameters");
	HI_DEBUG("this is a hi_debug test, has two parameters=>1:%s, 2:%d", "first parameter", 256);
	ASSERT_FALSE(isCalled);
}

TEST(HiCommonLog, set_debug_after_ignore){
	printf("we want log out put and ignore when call hi_is_ignore_debug begin\n");
	set_debug_after_ignore_test();
	printf("we want log out put and ignore when call hi_is_ignore_debug end\n");
}

static void set_debug_nullptr_test() {
	hi_is_ignore_debug(false);
	HI_DEBUG("this debug is out\n next will no log out");
	hi_set_debug(nullptr);
	HI_DEBUG("this debug is out, means this test is failed");	
}
TEST(HiCommonLog, set_debug_nullptr){
	printf("we want log out put and ignore when hi_set_debug param is nullptr begin\n");
	set_debug_nullptr_test();
	printf("we want log out put and ignore when hi_set_debug param is nullptr end\n");
}
